
package xj.graph2d.shapes.block;

import xj.graph2d.DrawShape;
import xj.graph2d.DrawShapeConstants;
import xj.graph2d.TextShape;

public class AttributeShape extends SimpleStatementShape {

  public AttributeShape() {
    this(false);
  }

  public AttributeShape(boolean createComp) {
    super(createComp);
    setStatementType(ATTRIBUTE);
  }

  public AttributeShape(float x1, float y1, float x2, float y2) { 
    this(x1, y1, x2, y2, false);
  }

  public AttributeShape(float x1, float y1, float x2, float y2, 
			boolean createComp) { 
    super(x1, y1, x2, y2, createComp);
    setStatementType(ATTRIBUTE);
  }

  @Override
  public DrawShape makeInstance() {
    return new AttributeShape(comp != null);
  }

  @Override
  public void setStatementType(int type) { 
    if (type != ATTRIBUTE &&
	type != STATIC_FIELD && 
	type != CONSTANT) { 
      type = ATTRIBUTE;
    }
    if (type != this.statementType) { 
      this.statementType = type; 
      
      TextShape textShape = null;
      DrawShape s = findInRole(DrawShapeConstants.ROLE_NODE_LABEL);
      if (s instanceof TextShape) { 
	textShape = (TextShape) s;
	int i = 0; 
	if (type == ATTRIBUTE) { 
	  i = 0; 
	} else if (type == STATIC_FIELD) { 
	  i = 1; 
	} else if (type == CONSTANT) { 
	  i = 2;
	}    
	setDisplayName(displayNames[i]); 
	textShape.setDisplayName(displayNames[i]); 
	textShape.setPrompt(prompts[i]);
	textShape.setPrefix(prefixes[i]);
      }
    }
  }

  String[] displayNames = {
    "Attribute",
    "Static Attribute",
    "Constant"
  };

  String[] prompts = {
    "Type attributeName",
    "Type attributeName",
    "Type constantName = value",
  };

  String[] prefixes = {
    null,
    "\u00ABstatic\u00BB ",
    "\u00ABconstant\u00BB ",
  };



}
